package com.wd.tech.activity.adaptert;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.wd.tech.R;
import com.wd.tech.activity.bean.QueryInformationCommentListBean;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @author 时文豪
 * @description:
 * @date :2020/7/14 16:39
 */
public class QueryInformationCommentAdaptert extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    Context context;
    List<QueryInformationCommentListBean.ResultBean> list;

    public QueryInformationCommentAdaptert(Context context, List<QueryInformationCommentListBean.ResultBean> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = View.inflate(context, R.layout.query_information_comment_item, null);
        return new MyComment(inflate);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        ((MyComment)holder).name.setText(list.get(position).getNickName());
        Glide.with(context).load(list.get(position).getHeadPic())
                .apply(RequestOptions.bitmapTransform(new RoundedCorners(20)))
                .into(((MyComment)holder).img);
        String format = new SimpleDateFormat("yy-MM-dd").format(new Date(list.get(position).getCommentTime()));
        ((MyComment) holder).time.setText(format);
        ((MyComment)holder).count.setText(list.get(position).getContent());
    }

    @Override
    public int getItemCount() {
        return list.size();
    }
    class MyComment extends RecyclerView.ViewHolder {

        private final TextView name;
        private final TextView time;
        private final TextView count;
        private final ImageView img;

        public MyComment(@NonNull View itemView) {
            super(itemView);
            name = itemView.findViewById(R.id.user_name);
            time = itemView.findViewById(R.id.user_time);
            count = itemView.findViewById(R.id.user_count);
            img = itemView.findViewById(R.id.user_img);
        }
    }
}
